﻿@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/MainPanel.cshtml";
}

@model BOSS.Domain.Products.Product

@section HeadContent 
{
    <script type="text/javascript">
        window.onInitUI = function () {
            var txtName = new Ext.form.TextField({
                name: 'Name',
                fieldLabel: '产品名称',
                width: 250,
                allowBlank: false
            });
            
            var txtModel = new Ext.form.TextField({
                name: 'Model',
                fieldLabel: '产品型号',
                width: 250,
                allowBlank: false
            });
            
            var txtSpecification = new Ext.form.TextField({
                name: 'Specification',
                fieldLabel: '产品规格',
                width: 250
            });
            
            var chkMarketable = new Ext.form.Checkbox({
                name: 'Marketable',
                fieldLabel: '可销售的',
                inputValue: true
            });
            
            var txtUseCount = new Ext.form.NumberField({
                name: 'UseCount',
                fieldLabel: '使用次数',
                allowDecimals: false,
                width: 250
            });
            
            var txtProcurementPrice = new Ext.form.NumberField({
                name: 'ProcurementPrice',
                fieldLabel: '采购价格',
                width: 250,
                value: '@(Model != null ? Model.ProcurementPrice : 0)'
            });
            
            var txtSellingPrice = new Ext.form.NumberField({
                name: 'SellingPrice',
                fieldLabel: '销售价格',
                width: 250
            });
            
            var formPanel = new Ext.form.FormPanel({
                renderTo: 'create',
                width: 400,
                border: true,
                frame: true,
                padding: '5px 5px 0 10px',
                buttonAlign: 'left',
                standardSubmit: true,
                buttons: [
                    { text: '提 交', type: 'submit', handler: function() { 
                        var form = formPanel.getForm();
                        if (form.isValid()) {
                            form.submit({ url: '@Url.Action("Create", "Product")' });
                        }
                    }}, 
                    { text: '重 置', handler: function() { formPanel.getForm().reset(); } }
                ],
                items: [ 
                    new Ext.utility.formRow([{ items: [txtName] }]),
                    new Ext.utility.formRow([{ items: [txtModel] }]),
                    new Ext.utility.formRow([{ items: [txtSpecification] }]),
                    new Ext.utility.formRow([{ items: [chkMarketable] }]),
                    new Ext.utility.formRow([{ items: [txtUseCount] }]),
                    new Ext.utility.formRow([{ items: [txtProcurementPrice] }]),
                    new Ext.utility.formRow([{ items: [txtSellingPrice] }])
                ]
            });
            @if (Model != null) {
                @Html.Raw(string.Format("txtName.setValue('{0}');", Model.Name))
                @Html.Raw(string.Format("txtModel.setValue('{0}');", Model.Model))
                @Html.Raw(string.Format("txtSpecification.setValue('{0}');", Model.Specification))
                @Html.Raw(string.Format("chkMarketable.setValue('{0}');", Model.Marketable.ToString().ToLower()))
                @Html.Raw(string.Format("txtUseCount.setValue('{0}');", Model.UseCount))
                @Html.Raw(string.Format("txtProcurementPrice.setValue('{0}');", Model.ProcurementPrice))
                @Html.Raw(string.Format("txtSellingPrice.setValue('{0}');", Model.SellingPrice))
            }           
        };
    </script>
}

<div id="create" style="margin: 5px;"></div>
